1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: XSLServletContext.java,v 1.9 2002/09/05 15:41:51 ludovicc Exp $
37 */
38 package org.scopemvc.controller.servlet.xml;
39
40
41 import java.io.IOException;
42 import java.util.HashMap;
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
47 import org.scopemvc.core.View;
48 import org.scopemvc.view.servlet.Page;
49 import org.scopemvc.view.servlet.ServletView;
50 import org.scopemvc.view.servlet.xml.AbstractXSLPage;
51 import org.scopemvc.controller.servlet.ScopeServlet;
52 import org.scopemvc.controller.servlet.ServletContext;
53
54 /***
55 * <P>
56 *
57 * A {@link org.scopemvc.controller.servlet.ServletContext ServletContext} that
58 * that shows {@link org.scopemvc.view.servlet.xml.AbstractXSLPage}s. </P>
59 *
60 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A>
61 * @created 05 September 2002
62 * @version $Revision: 1.9 $ $Date: 2002/09/05 15:41:51 $
63 */
64 public class XSLServletContext extends ServletContext {
65
66 private final static Log LOG = LogFactory.getLog(XSLServletContext.class);
67
68
69 /***
70 * Create with an HttpServletResponse to use on a showView during
71 * initialisation, and a HttpServletRequest accessible to application code.
72 *
73 * @param inServlet TODO: Describe the Parameter
74 * @param inRequest TODO: Describe the Parameter
75 * @param inResponse TODO: Describe the Parameter
76 * @param inFormParameters TODO: Describe the Parameter
77 */
78 public XSLServletContext(ScopeServlet inServlet,
79 HttpServletRequest inRequest,
80 HttpServletResponse inResponse,
81 HashMap inFormParameters) {
82 super(inServlet, inRequest, inResponse, inFormParameters);
83 }
84
85
86 /***
87 * Show the ServletView passed, setting the response's ContentType via a
88 * call to {@link org.scopemvc.view.servlet.xml.AbstractXSLPage#getContentType}.
89 *
90 * @param inView TODO: Describe the Parameter
91 */
92 public void showView(View inView) {
93 if (LOG.isDebugEnabled()) {
94 LOG.debug("showView: " + inView);
95 }
96 if (!(inView instanceof ServletView)) {
97 throw new IllegalArgumentException("XSLServletContext can only show Views that are instanceof ServletView, not: " + inView);
98 }
99 if (response == null) {
100 throw new UnsupportedOperationException("Can't show the view because don't have a HTTPServletResponse.\nHas a view already been shown during this servlet request?");
101 }
102
103 try {
104 Page visiblePage = ((ServletView) inView).getVisible();
105 if (!(visiblePage instanceof AbstractXSLPage)) {
106 throw new IllegalArgumentException("XSLServletContext can only show Pages that are instanceof AbstractXSLPage, not: " + visiblePage);
107 }
108
109 response.setContentType(((AbstractXSLPage) visiblePage).getContentType());
110 ((AbstractXSLPage) visiblePage).streamView(response.getOutputStream());
111 response.getOutputStream().close();
112
113 } catch (Exception e) {
114 // Could be client broke the connection by pressing "Stop" or something...
115 if (LOG.isDebugEnabled()) {
116 LOG.debug("doShowView", e);
117 }
118 try {
119 handleInternalError(e);
120 } catch (IOException e1) {
121 if (LOG.isDebugEnabled()) {
122 LOG.debug("doShowView", e1);
123 }
124 }
125 } finally {
126 response = null;
127 }
128 }
129 }
This page was automatically generated by Maven